package org.openspml.providers.one_c.api.users;

import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

/**
 * @author <A href="mailto:abashev at gmail dot com">Alexey Abashev</A>
 * @version $Id$
 */
public class InfoBaseUser extends Dispatch {
	public InfoBaseUser(Dispatch dispatch) {
		super(dispatch);
	}
	
	public String getName() {
		return Dispatch.get(this, "Name").getString();
	}

	public void setName(String name) {
		Dispatch.put(this, "Name", name);
	}

	public String getFullName() {
		return Dispatch.get(this, "FullName").getString();
	}

	public void setFullName(String fullName) {
		Dispatch.put(this, "FullName", fullName);
	}

	public String getLanguage() {
		Variant variant = Dispatch.get(this, "Language");
		
		if (variant.getvt() == Variant.VariantEmpty) {
			return null;
		}

		return Dispatch.get(variant.toDispatch(), "Name").getString();
	}

	public String getDefaultInterface() {
		Variant variant = Dispatch.get(this, "DefaultInterface");
		
		if (variant.getvt() == Variant.VariantEmpty) {
			return null;
		}

		return Dispatch.get(variant.toDispatch(), "Name").getString();
	}

// Write only
//	public String getPassword() {
//		return Dispatch.get(this, "Password").getString();
//	}

	public void setPassword(String password) {
		Dispatch.put(this, "Password", password);
	}

	public boolean isSetPassword() {
		return Dispatch.get(this, "PasswordIsSet").getBoolean();
	}
	
	public boolean isShowInList() {
		return Dispatch.get(this, "ShowInList").getBoolean();
	}

	public void setShowInList(boolean showInList) {
		Dispatch.put(this, "ShowInList", showInList);
	}
	
	public String getOSUser() {
		return Dispatch.get(this, "OSUser").getString();
	}
	
	public boolean containsRole(UserRole role) {
		Dispatch roles = Dispatch.get(this, "Roles").toDispatch();

		return Dispatch.call(roles, "Contains", role).getBoolean();
	}

	public void clearRoles() {
		Dispatch roles = Dispatch.get(this, "Roles").toDispatch();

		Dispatch.call(roles, "Clear");
	}
	
	public String getUUID() {
		return Dispatch.get(this, "UUID").getString();
	}

	public boolean isOSAuthentication() {
		return Dispatch.get(this, "OSAuthentication").getBoolean();
	}

	public void setOSAuthentication(boolean authentication) {
		Dispatch.put(this, "OSAuthentication", authentication);
	}

	public boolean isStandardAuthentication() {
		return Dispatch.get(this, "StandardAuthentication").getBoolean();
	}

	public void setStandardAuthentication(boolean authentication) {
		Dispatch.put(this, "StandardAuthentication", authentication);
	}

	public boolean canChangePassword() {
		return !Dispatch.get(this, "CannotChangePassword").getBoolean();
	}

	public void setCanChangePassword(boolean canChangePassword) {
		Dispatch.put(this, "CannotChangePassword", !canChangePassword);
	}

	public void write() {
		Dispatch.call(this, "Write");
	}
	
	public void delete() {
		Dispatch.call(this, "Delete");
	}
}
